package com.charlie.beans;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Вова
 */
@Entity
@Table(name = "GROUPS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Groups.findAll", query = "SELECT g FROM Groups g"),
    @NamedQuery(name = "Groups.findByGroupsId", query = "SELECT g FROM Groups g WHERE g.groupsId = :groupsId")})
public class Groups implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @SequenceGenerator(name = "GROUPS_SEQ", sequenceName = "GROUPS_GROUPS_ID_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GROUPS_SEQ")    
    @Column(name = "GROUPS_ID")
    private Integer groupsId;
   // @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "NAME")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "groupsId")
    private Collection<GroupsRoles> groupsRolesCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "groupsId")
    private Collection<UsersGroups> usersGroupsCollection;

    public Groups() {
    }

    public Groups(Integer groupsId) {
        this.groupsId = groupsId;
    }

    public Integer getGroupsId() {
        return groupsId;
    }

    public void setGroupsId(Integer groupsId) {
        this.groupsId = groupsId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<GroupsRoles> getGroupsRolesCollection() {
        return groupsRolesCollection;
    }

    public void setGroupsRolesCollection(Collection<GroupsRoles> groupsRolesCollection) {
        this.groupsRolesCollection = groupsRolesCollection;
    }

    @XmlTransient
    public Collection<UsersGroups> getUsersGroupsCollection() {
        return usersGroupsCollection;
    }

    public void setUsersGroupsCollection(Collection<UsersGroups> usersGroupsCollection) {
        this.usersGroupsCollection = usersGroupsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (groupsId != null ? groupsId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Groups)) {
            return false;
        }
        Groups other = (Groups) object;
        if ((this.groupsId == null && other.groupsId != null) || (this.groupsId != null && !this.groupsId.equals(other.groupsId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.charlie.beans.Groups[ groupsId=" + groupsId + " ]";
    }
}
